package com.ysh.controller;

import com.ysh.domain.Student;
import com.ysh.service.StudentService;
import com.ysh.service.StudentServiceImpl;
import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class StudentController {
    StudentService service = new StudentServiceImpl();
    /*
        查询所有学生信息
     */
   @Test
    public void findAll(){
       ArrayList<Student> list = service.findAll();
       for (Student student : list) {
           System.out.println(student);
       }
   }
   /*
       根据id查询学生信息
    */
   @Test
    public void findById(){
       Student stu = service.findById(4);
       System.out.println(stu);
   }
   /*
       新增学生信息
    */
   @Test
    public void insert(){
       Student stu = null;
       try {
           stu = new Student(5,"赵丽颖",33,new SimpleDateFormat("yyyy-MM-dd").parse("1987-10-16"));
       } catch (ParseException e) {
           e.printStackTrace();
       }
       int insert = service.insert(stu);
       if (insert != 0){
           System.out.println("添加成功");
       }else{
           System.out.println("添加失败");
       }
   }
   /*
       修改学生信息
    */
   @Test
   public void update(){
       Student stu = service.findById(3);
       stu.setName("李四四");

       int result = service.update(stu);
       if (result != 0){
           System.out.println("修改成功");
       }else{
           System.out.println("修改失败");
       }
       findAll();
   }
   /*
       删除学生信息
    */
   @Test
    public void delete(){
       int result = service.delete(3);
       if (result != 0){
           System.out.println("删除成功");
       }else{
           System.out.println("删除失败");
       }
       findAll();
   }
}
